#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin; export PATH

# ------------------------------------------------------------
# set file permissions
for f in \
    '/Applications/Karabiner.app' \
    '/Library/Application Support/org.pqrs/Karabiner' \
    '/Library/LaunchDaemons/org.pqrs.Karabiner.load.plist' \
    ; do
    echo "set file permissions: $f"
    sh '/Library/Application Support/org.pqrs/Karabiner/setpermissions.sh' "$f"
    chown -Rh root:wheel "$f"
done

# ------------------------------------------------------------
# relaunch Karabiner

killall -USR2 Karabiner

# ------------------------------------------------------------
# load kext
# (We have to load kext after relaunch Karabiner.app to avoid "kext version mismatched alert".)
sh "/Library/Application Support/org.pqrs/Karabiner/startup.sh" start

# ------------------------------------------------------------
exit 0
